package cn.gson.boot.controller;

import cn.gson.boot.model.pojos.Kefu;
import cn.gson.boot.model.pojos.Tousu;
import cn.gson.boot.model.service.KeFuService;
import cn.gson.boot.model.service.TouSuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/tousu")
public class TouSuController {
    @Autowired
    TouSuService touSuService;

    //新增客服
    @RequestMapping("/addTouSu")
    @ResponseBody
    public void addTouSu(@RequestBody Tousu tousu){
        touSuService.addTouSu(tousu);
    }

    //查询所有投诉
    @RequestMapping("/selectAllTouSu")
    @ResponseBody
    public Map<String,Object> selectAllTouSu(String kName,String time, Integer pageNumm, Integer pageSizee){
        Page<Object> objects = PageHelper.startPage(pageNumm, pageSizee);

        String time3 = null;
        if(time != null && time != "" && !time.equals("")){
            StringBuffer time1 = new StringBuffer(time.substring(0,10));
            System.err.println("tim1:"+time1);
            int ti = Integer.parseInt(time1.substring(8))+1;
            System.err.println("ti:"+ti);
            String tistr = toString().valueOf(ti);
            if(toString().valueOf(ti).length() == 1){
                tistr = 0 + toString().valueOf(ti);
            }
            StringBuffer time2 = new StringBuffer(time1.replace(8,time1.length(), tistr));
            System.err.println("tim2:"+time2);
            time3 = time2.toString();
        }
        List<Tousu> list = touSuService.selectAllTouSu(kName,time3);

        Map<String,Object> map = new HashMap();
        map.put("total", objects.getTotal());
        map.put("list", list);
        return map;
    }

    //移除投诉
    @RequestMapping("/yichuTouSu")
    @ResponseBody
    public void yichuKeFu(Integer tsId){
       touSuService.yichuKeFu(tsId);
    }
}
